import {forwardRef, useImperativeHandle, useRef} from 'react'
import { Ifoucs } from './index'

// useImperativeHandle 用于子组件暴露方法给Ref
type Iprops = {
    name:string
}
const Child = forwardRef<Ifoucs,Iprops>((props,ref) => {
    // 给input创建Ref
    let ipt = useRef<HTMLInputElement | null>(null)
    useImperativeHandle(ref,()=>{
        return{
            getFocus(){
                console.log(13);
                ipt.current!.focus()
                return true
            }
        }
    })
    return(
        <fieldset>
            <legend>子组件</legend>
            <input ref={ipt} type="text"/>
        </fieldset>
    )
})
export default Child